import React from "react";
import { useLocation , useParams } from "react-router-dom";
import qs from 'querystring'


export default function Detail() {
    // 使用params传参
    // const { id } = useParams()

    // 接收search传递的参数
    // const { id } = qs.parse(useLocation().search.slice(1));

    // 接收state传递的参数
    const { state: obj } = useLocation();
    let { id, title, content } = obj
    


    const MessageData = [
        { id: 1, title: "1233", content: "我真帅" },
        { id: 2, title: "4566", content: "中国真好" },
        { id: 3, title: "7899", content: "我还是很帅" },
    ];
    

    // let { title, content } = MessageData.find( ( obj ) => {
    //     return obj.id === parseInt(id)
    // })
    
    return (
        <div>
            id: {id}<br />
            title: {title}
            <br />
            content:{content}
            <br />
        </div>
    );
}
